import Vuex from "vuex"
import Vue from "vue"

Vue.use(Vuex)
export default new Vuex.Store({
    state:{
        name:"张三",
        orderInfo:[],
        actionShow : false,
        content:0
    },
    mutations:{
        changeName(state,val){
            state.name = val
        },
        getData(state,val){
            val.map((item:any)=>{
                item.foods.map((child:any)=>{
                    return child.num = 0
                })
            })
            state.orderInfo = val
            console.log(state.orderInfo);
        },
        add(state,nObj:any):void{
            const a:any = state
            for(const obj of a.orderInfo){
                for(const child of obj.foods){
                    if(child.id==nObj.id){
                        child.num+=nObj.num
                    }
                }
            }
            state.content +=nObj.num
        }
    },
    getters:{
        shopCartList(state):any{
            const newArr:Array<any> = []
            const a:any = state
            for(const obj of a.orderInfo){
                for(const child of obj.foods){
                    if(child.num>0){
                      newArr.push(child)
                    }
                }
            }
            return newArr
        },
        getNum(state):any{
            const newArr:Array<any> = []

        }
    }
})